﻿@model SIGCBI.WebMVC4.Models.RegisterModel

@{
    ViewBag.Title = "Administración de Usuarios";
}


<link rel="stylesheet" href="~/Content/bootstrap.min.css">



<link rel="stylesheet" href="~/Content/bootstrap.min.css">
<link rel="stylesheet" href="~/Content/themes/base/jquery-ui.css">
<script src="~/Scripts/jquery-1.10.2.js"></script>
<script src="~/Scripts/jquery-ui.js"></script>

<hgroup class="title">
    <h1>@ViewBag.Title</h1>
</hgroup>

<script>
    $(function () {
        $("#tabs").tabs({
            collapsible: true
        });
    });
</script>

<h3><span class="field-validation-error">@ViewBag.ResultMessage</span></h3>
@*<div class="message-success">@ViewBag.ResultMessage</div>*@
<h2>@Html.ValidationSummary()</h2>

<div id="tabs">

    <ul>
        <li><a href="#TabAddRolUser">Asignar Rol a Usuario</a></li>
        <li><a href="#TabDeleteRolUser">Quitar Rol a Usuario</a></li>
        <li><a href="#TabUsuarios">Lista de Usuarios</a></li>
        <li><a href="#TabAddUsuarios">Registro de Usuarios</a></li>
    </ul>

    <div id="TabAddRolUser">
        <section id="AddRolUser">

            <div class="panel panel-default">
                <div class="panel-heading">Roles por Usuario</div>
                <div class="panel-body">
                    @using (Html.BeginForm("GetRoles", "Rol"))
                    {
                        @Html.AntiForgeryToken()
                        <p>
                            Usuario: @Html.TextBox("UserName")
                            <input type="submit" value="Obtener Roles de este Usuario" />
                        </p>
                    }

                    @if (ViewBag.RolesForThisUser != null)
                    {
                        <text>
                        <h3>Roles asignados al Usuario</h3>
                        <ol>
                            @foreach (string s in ViewBag.RolesForThisUser)
                            {
                                <li>@s</li>   
                            }
                        </ol>
                        </text>
                    }
                </div>
                <div class="panel-footer"></div>
            </div>



            <div id="dialog" class="panel panel-default">
                <div class="panel-heading">Asignar Rol a Usuario</div>
                <div class="panel-body">
                    @using (Html.BeginForm("RoleAddToUser", "Rol"))
                    {
                        @Html.AntiForgeryToken()
                        
                        <p>
                            Usuario: @Html.TextBox("UserName") @Html.DropDownList("RoleName", ViewBag.Roles as SelectList)
                        </p>
                        <br />
                        <input type="submit" value="Asignar Rol" />
                    }
                </div>
                <div class="panel-footer"></div>
            </div>

        </section>
    </div>

    <div id="TabDeleteRolUser">
        <section id="DeleteRolUser">

            <div class="panel panel-default">
                <div class="panel-heading">Quitar Rol a Usuario</div>
                <div class="panel-body">

                    @using (Html.BeginForm("DeleteRoleForUser", "Rol"))
                    {
                        @Html.AntiForgeryToken()
                        
                        <p>
                            Usuario : @Html.TextBox("UserName")
                            Role: @Html.DropDownList("RoleName", ViewBag.Roles as SelectList)

                        </p>
    
                        <input type="submit" value="Quitar Rol a Usuario" />
                    }
                </div>
                <div class="panel-footer"></div>
            </div>

        </section>
    </div>

    <div id="TabUsuarios">
        <section class="social" id="Usuarios">

            <div class="panel panel-default">
                <div class="panel-heading">Lista de Usarios</div>
                <div class="panel-body">
                    @using (Html.BeginForm("GetUsers", "Rol"))
                    {
                        @Html.AntiForgeryToken()
                        <p>
                            Usuario : @Html.TextBox("NameUser")
                            <input type="submit" value="Obtener todos los usuarios" />
                        </p>
        
                        <table class="table table-striped table-bordered">
                            <tr class="danger">
                                <th>Usuario</th>
                                <th>Acción</th>
                            </tr>

                            @foreach (var item in ViewBag.AllUsers)
                            {
                                <tr>
                                    <td> @item </td>
                                    <td>
                                        <span onclick="return confirm('Seguro que desea eliminar este usuario?')">
                                            <a href="@Url.Action("UsuarioDelete", "Rol", new { UserName = item })" class = "deleteLink">
                                                <img src="@Url.Content("~/Images/delete.png")" title="Eliminar Usuario" alt="Eliminar Usuario" /></a>
                                        </span>
                                    </td>
                                </tr>
                            }

                        </table>
                    }
                </div>
                <div class="panel-footer"></div>
            </div>

        </section>
    </div>

    <div id="TabAddUsuarios">

        <section id="AddUsuarios">

            <div class="panel panel-default">
                <div class="panel-heading">Cree una cuenta nueva</div>
                <div class="panel-body">

                    @using (Html.BeginForm("Register", "Rol"))
                    {
                        @Html.AntiForgeryToken()
                        
                        <fieldset>
                            <legend>Formulario de registro</legend>
                            <ol>
                                <li>
                                    @Html.LabelFor(m => m.UserName)
                                    @Html.TextBoxFor(m => m.UserName)
                                </li>
                                <li>
                                    @Html.LabelFor(m => m.Password)
                                    @Html.PasswordFor(m => m.Password)
                                </li>
                                <li>
                                    @Html.LabelFor(m => m.ConfirmPassword)
                                    @Html.PasswordFor(m => m.ConfirmPassword)
                                </li>
                            </ol>
                            <input type="submit" value="Registrar Usuario" />
                        </fieldset>
                    }
                </div>
                <div class="panel-footer"></div>
            </div>

        </section>

    </div>


</div>
@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
}
